<template>
  <basic-container>
    <div class="card-border">
      <card-header :header-data="headerData" @buttonClick="handleAdd()"></card-header>
      <div class="card-body">
        <avue-crud :data="messageData"
                   :option="messageoption"
                   :page="messagepage"
                   :table-loading="tableLoading"
                   @on-load="getMessageList"
                   @refresh-change="refreshChange"
                   @search-change="searchChange">
          <template slot-scope="scope" slot="menu">
            <div class="menu-title" @click.stop="feedBack(scope.row)">
              <i class="iconfont iconview" style="color: #409EFF;"></i>
              <p class="menu-title-text">反馈</p>
            </div>
            <div class="menu-title" @click.stop="haveReadContent(scope.row)" v-if="scope.row.haveRead==false">
              <i class="iconfont iconalter icon-warning"></i>
              <p class="menu-title-text">标为已读</p>
            </div>
          </template>
        </avue-crud>
      </div>
    </div>
  </basic-container>
</template>
<script>
  import {getunreadMsg, toHaveRead} from "@/api/system";
  import {SYS_DIC} from '@/const/dict'

  export default {
    name: "levyFeedbackList",
    data() {
      return {
        headerData: {
          title: '未办理反馈'
        },
        tableLoading: false,
        unreadFlag: false,//是否未读标志
        messagepage: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        messageData: [],
        messageoption: {
          page: true,
          addBtn: false,
          editBtn: false,
          addRowBtn: false,
          indexLabel: "序号",
          index: true,
          indexWidth:70,
          cellBtn: false,
          delBtn: false,
          columnBtn: false,
          refreshBtn: false,
          filterBtn: false,
          searchBtn: false,
          menuWidth: 200,
          keyId: "id",
          column: [
            {
              label: "消息内容",
              prop: "content",
              width: 400,
              cell: true
            },
            {
              label: "发送时间",
              prop: "sendTime",
              cell: true
            },
            {
              label: "是否已读",
              prop: "haveRead",
              dicData: SYS_DIC.MSGREAD,
              cell: true
            },
          ]
        }
      };
    },
    created() {
      this.unreadFlag = this.$route.params.id;
      if (this.unreadFlag == 'true') {
        this.headerData.title = '已办理反馈'
      }
      this.getMessageList();
    },
    methods: {
      // 获取消息列表信息
      getMessageList(page, params) {
        this.tableLoading = true;
        getunreadMsg(Object.assign({
          current: page.currentPage,
          size: page.pageSize,
          haveRead: this.unreadFlag,
          module: '1'
        }, params)).then(response => {
          if (response.data.code == '0') {
            this.messageData = response.data.data.records;
            this.messagepage.total = response.data.data.total;
            this.$emit("getTotal", response.data.data.total);
            this.tableLoading = false;
          }
        })
      },

      /**
       * 刷新回调
       */
      refreshChange() {
        this.getMessageList(this.messagepage)
      },
      // 查询回调
      searchChange(params) {
        this.messagepage.currentPage = 1
        this.getMessageList(this.messagepage, params)
      },
      //点击反馈row.businessKey为collectionID
      feedBack(row) {
        let src = row.formKey + '/' + row.businessKey;
        this.$router.push({
          path: src,
        })
      },
      //已读消息点击详情
      haveReadContent(row) {
        this.$confirm("确定将此条消息标为已读吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          toHaveRead(Object.assign({
            messageIds: row.messageId
          })).then(response => {
            if (response.data.code == 0) {
              this.$notify({
                title: '成功',
                message: '调整成功',
                type: 'success',
                duration: 2000
              });
              this.getMessageList(this.messagepage);
            }
          })
        })
      }
    }
  };
</script>

<style lang="scss" scoped>
  .card-border {
    border: 1px solid #d2d2d2;
  }

  .card-body {
    padding: 10px;
  }
</style>
